home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tcclib.exe / SFWIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-31  |  1.9 KB  |  68 lines

  1. #include <conio.h>
  2. #include <alloc.h>
  3. #include <mem.h>
  4. #include <string.h>
  5. #include <assert.h>
  6. #include "window.h"
  7. #include "_window.h"
  8.  
  9. /* shiftwindow() ---------------------------------------------------
  10.  *    Make a window the current window.
  11.  *    RETURN: 0 Success, 1 Out of memory
  12.  * -----------------------------------------------------------------
  13.  */
  14. int shiftwindow(windowtype *awindow)
  15. {
  16.     char *forscreen;
  17.  
  18.     /* If it is already the current window, we don't neeed to shift it */
  19.     if (windowchain == awindow)
  20.         return (int) windowerr = WE_OK;
  21.  
  22.     /* Store the current window's cursor coordinates */
  23.     windowchain->xpos = wherex();
  24.     windowchain->ypos = wherey();
  25.  
  26.     /* Get the image to place on the screen */
  27.     if ( (forscreen = getwinimage(awindow,0)) == NULL )
  28.     {
  29.         free(forscreen);
  30.         return (int) windowerr = WE_OMEM;
  31.     }
  32.  
  33.     /* Distribute the backbuffer */
  34.     if ( putwinimage(awindow,awindow->backbuffer,0,0) != 0 )
  35.         return (int) windowerr = WE_OMEM;
  36.  
  37.     /* Delete the window from current position and insert it on top */
  38.     if (awindow->next)
  39.         awindow->next->previous = awindow->previous;
  40.     if (awindow->previous)
  41.         awindow->previous->next = awindow->next;
  42.  
  43.     if (windowchain != NULL )
  44.         windowchain->previous = awindow;
  45.     awindow->previous = NULL;
  46.     awindow->next = windowchain;
  47.     windowchain = awindow;
  48.  
  49.     /* Write the forscreen to the screen, this will actually "pop-up"
  50.      * the window.
  51.      */
  52.     puttext(awindow->left,awindow->top,awindow->right,awindow->bottom,
  53.             forscreen);
  54.  
  55.     /* Section off the screen for the window and put the cursor back
  56.      * where it was before the window was made non-current
  57.      */
  58.     window(awindow->left+1,awindow->top+1,awindow->right-1,awindow->bottom-1);
  59.     gotoxy(awindow->xpos,awindow->ypos);
  60.     textattr(awindow->attr);
  61.  
  62.     /* Free allocated memory */
  63.     free(forscreen);
  64.  
  65.     /* Tell the user everythings OK */
  66.     return (int) windowerr = WE_OK;
  67. }
  68.